<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
</head>
<body>
<div id="app">
    商品产地：<input type="text" v-model="goods.city">
    <p>{{message}}</p>
</div>
<!--引入vue文件-->
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script>
    const vm = Vue.createApp({
        data() {
            return {
                message: '',
                goods: {
                    name: '洗衣机',
                    city: ''
                }
            }
        },
        watch: {
            // 监听goods对象的city属性
            'goods.city': {
                handler: function(newValue, oldValue) {
                    if (newValue == "上海") {
                        this.message = "商品的产地是上海！";
                    }
                    else {
                        this.message = "商品的产地不是上海！"
                    }
                },
                // 设置为true，无论属性被嵌套多深，改变时都会调用handler函数
                deep: true
            }
        }
    }).mount('#app');
</script>


</body>
</html>
